package com.mr.cai.main.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mr.cai.main.R;
import com.mr.cai.main.bean.TicketsInfoBean;

/**
 * Created by hai8108 on 16/2/11.
 */
public class TicketsAdapter extends MrCaiBaseAdapter {
    public TicketsAdapter (Activity context) {
        super(context);
    }
    @Override
    public View getView (int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(getList() == null || getList().size() <=0){
            return null;
        }
        final int index = position;
        TicketsInfoBean mTicketsInfoBean = (TicketsInfoBean) getItem(position);
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView= View.inflate(mContext, R.layout.setting_activity_tickets_item_layout,null);
            viewHolder.topIv = (ImageView) convertView.findViewById(R.id.mr_cai_top_iv);
            viewHolder.ticketsStatusIV = (ImageView) convertView.findViewById(R.id.tickets_status_iv);
            viewHolder.ticketsDesc = (TextView) convertView.findViewById(R.id.mr_cai_tickets_type_tv);
            viewHolder.ticketsDetail = (TextView) convertView.findViewById(R.id
                    .mr_cai_tickets_detail);
            viewHolder.ticketstime = (TextView) convertView.findViewById(R.id.mr_cai_tickets_time);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if(mTicketsInfoBean.getStatus() == 0){
            viewHolder.ticketsStatusIV.setImageResource(R.drawable.mr_cai_tickets_intime_bg);
        } else {
            viewHolder.ticketsStatusIV.setImageResource(R.drawable.mr_cai_tickets_status_used_bg);
        }
        viewHolder.ticketsDesc.setText(mTicketsInfoBean.getTypeName());
        viewHolder.ticketsDetail.setText("￥"+mTicketsInfoBean.getPrice()+"    "+mTicketsInfoBean
                .getDetailDiscrib());
        viewHolder.ticketstime.setText("使用期限: "+mTicketsInfoBean.getValidTime());
        return convertView;
    }
    public static  class ViewHolder{
        private ImageView topIv;
        private ImageView ticketsStatusIV;
        private TextView ticketsDesc;
        private TextView ticketsDetail;
        private TextView ticketstime;
    }
}
